//
//  WPOrderCompeleteCell.m
//  ZhongChouPingTai
//
//  Created by WeiPan on 16/4/7.
//  Copyright © 2016年 WPJoe. All rights reserved.
//

#import "WPOrderCompeleteCell.h"

@interface WPOrderCompeleteCell ()
@property (nonatomic, strong) UILabel * titleLabel;/**< 标题 */
@property (nonatomic, strong) UILabel * statusLabel;/**< 状态文本 */
@property (nonatomic, strong) UIView * orderBackView;/**< 灰色背景 */
@property (nonatomic, strong) UIImageView * activeImageView;/**< 活动海报 */
@property (nonatomic, strong) UITextField * moneyTextField;/**< 金额展示 */
@property (nonatomic, strong) UITextField * orderNumTextField;/**< 订单编号展示 */
@property (nonatomic, strong) UILabel * numCountLabel;/**< 数量合计 */
@property (nonatomic, strong) UIButton * deleteOrderBtn;/**< 删除订单 */
@property (nonatomic, strong) UIButton * showRightBtn;/**< 查看权益 */

- (void)initializeAppearance;/**< 一般界面初始化 */
@end
@implementation WPOrderCompeleteCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self initializeAppearance];
    }
    return self;
}

#pragma mark - init
- (void)initializeAppearance {
    self.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.titleLabel];
    [self addSubview:self.statusLabel];
    [self addSubview:self.orderBackView];
//    [self addSubview:self.deleteOrderBtn];
    [self addSubview:self.showRightBtn];
}
#pragma mark - responds events
- (void)respondsToDeleteBtn {
    if (self.delegate && [_delegate respondsToSelector:@selector(deleteOrderWithOrderModel:)]) {
        [_delegate deleteOrderWithOrderModel:_model];
    }
}
- (void)respondsToShowRightBtn {
    if (self.delegate && [_delegate respondsToSelector:@selector(checkTicketRightWithOrderModel:)]) {
        [_delegate checkTicketRightWithOrderModel:_model];
    }
}
- (void)setModel:(WPOrderModel *)model {
    _model = model;
    _titleLabel.text = model.orderName;
    switch ([model.orderStatus integerValue]) {
        case 0:
            _statusLabel.text = @"待付款";
            _statusLabel.textColor = COLOR_RGB(237, 27, 47, 1);
            break;
        case 1:
            _statusLabel.text = @"已付款";
            _statusLabel.textColor = COLOR_RGB(101, 101, 101, 1);
            break;
        case 2:
            _statusLabel.text = @"已出票";
            _statusLabel.textColor = COLOR_RGB(101, 101, 101, 1);

            break;
        case 3:
            _statusLabel.text = @"已取消";
            _statusLabel.textColor = COLOR_RGB(101, 101, 101, 1);
            break;
  
        default:
            break;
    }
    _moneyTextField.text = [NSString stringWithFormat:@"¥ %@", model.amountPaid];
    _orderNumTextField.text = model.sn;
    _numCountLabel.text = [NSString stringWithFormat:@"共计%@件商品", model.quantity];
}
#pragma mark - getter
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 0, 200*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier())];
            lab.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            lab;
        });
    }
    return _titleLabel;
}
- (UILabel *)statusLabel {
    if (!_statusLabel) {
        _statusLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.titleLabel.frame), CGRectGetMinY(self.titleLabel.frame), 100*DHFlexibleHorizontalMutiplier(), CGRectGetHeight(self.titleLabel.frame))];
            lab.font = [UIFont systemFontOfSize:13*DHFlexibleHorizontalMutiplier()];
            lab.textAlignment = NSTextAlignmentRight;
            lab;
        });
    }
    return _statusLabel;
}
- (UIView *)orderBackView {
    if (!_orderBackView) {
        _orderBackView = ({
            UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(self.titleLabel.frame), SCREEN_SIZE.width, 90*DHFlexibleHorizontalMutiplier())];
            view.backgroundColor = BGCOLOR;
            [view addSubview:self.activeImageView];
            [view addSubview:self.moneyTextField];
            [view addSubview:self.numCountLabel];
            [view addSubview:self.orderNumTextField];
            view;
        });
    }
    return _orderBackView;
}
- (UIImageView *)activeImageView {
    if (!_activeImageView) {
        _activeImageView = ({
            UIImageView * view = [[UIImageView alloc]initWithFrame:CGRectMake(10*DHFlexibleHorizontalMutiplier(), 5*DHFlexibleHorizontalMutiplier(), 75*DHFlexibleHorizontalMutiplier(), 75*DHFlexibleHorizontalMutiplier())];
            view.layer.cornerRadius = 5*DHFlexibleHorizontalMutiplier();
            view.layer.masksToBounds = YES;
            view.image = IMAGE_NAME(@"banner1");
            view;
        });
    }
    return _activeImageView;
}
- (UITextField *)moneyTextField {
    if (!_moneyTextField) {
        _moneyTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMaxX(self.activeImageView.frame)+10*DHFlexibleHorizontalMutiplier(), 15*DHFlexibleHorizontalMutiplier(), 200, 20*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 65*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(153, 153, 153, 1);
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.text = @"订单金额：";
            text.leftView = lab;
            text.userInteractionEnabled = NO;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(96, 96, 96, 1);
            text;
        });
    }
    return _moneyTextField;
}

- (UITextField *)orderNumTextField {
    if (!_orderNumTextField) {
        _orderNumTextField = ({
            UITextField * text = [[UITextField alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.moneyTextField.frame), 35*DHFlexibleHorizontalMutiplier(), 200, 20*DHFlexibleHorizontalMutiplier())];
            text.leftViewMode = UITextFieldViewModeAlways;
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 65*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(153, 153, 153, 1);
            lab.font = [UIFont systemFontOfSize:11*DHFlexibleHorizontalMutiplier()];
            lab.text = @"订单编号：";
            text.leftView = lab;
            text.userInteractionEnabled = NO;
            text.font = [UIFont systemFontOfSize:14*DHFlexibleHorizontalMutiplier()];
            text.textColor = COLOR_RGB(96, 96, 96, 1);
            text;
        });
    }
    return _orderNumTextField;
}
- (UILabel *)numCountLabel {
    if (!_numCountLabel) {
        _numCountLabel = ({
            UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(self.orderNumTextField.frame), CGRectGetMaxY(self.orderNumTextField.frame), 240*DHFlexibleHorizontalMutiplier(), 25*DHFlexibleHorizontalMutiplier())];
            lab.textColor = COLOR_RGB(107, 107, 107, 1);
            lab.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            lab.text = @"共计1件商品";
            lab;
        });
    }
    return _numCountLabel;
}

- (UIButton *)deleteOrderBtn {
    if (!_deleteOrderBtn) {
        _deleteOrderBtn = ({
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(180*DHFlexibleHorizontalMutiplier(), CGRectGetMaxY(self.orderBackView.frame)+10*DHFlexibleHorizontalMutiplier(), 60*DHFlexibleHorizontalMutiplier(), 20*DHFlexibleHorizontalMutiplier());
            btn.layer.borderWidth = 1;
            btn.layer.borderColor = COLOR_RGB(181, 181, 181, 1).CGColor;
            [btn setTitleColor:COLOR_RGB(181, 181, 181, 1) forState:UIControlStateNormal];
            [btn setTitle:@"删除订单" forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            [btn addTarget:self action:@selector(respondsToDeleteBtn) forControlEvents:UIControlEventTouchUpInside];
            btn;
        });
    }
    return _deleteOrderBtn;
}
- (UIButton *)showRightBtn {
    if (!_showRightBtn) {
        _showRightBtn = ({
            UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
            btn.frame = CGRectMake(250*DHFlexibleHorizontalMutiplier(), CGRectGetMinY(self.deleteOrderBtn.frame), 60*DHFlexibleHorizontalMutiplier(), 30*DHFlexibleHorizontalMutiplier());
            btn.layer.cornerRadius = 3*DHFlexibleHorizontalMutiplier();
            btn.layer.borderWidth = 1;
            btn.layer.borderColor = COLOR_RGB(181, 181, 181, 1).CGColor;
            [btn setTitleColor:COLOR_RGB(181, 181, 181, 1) forState:UIControlStateNormal];
            [btn setTitle:@"查看详情" forState:UIControlStateNormal];
            btn.titleLabel.font = [UIFont systemFontOfSize:12*DHFlexibleHorizontalMutiplier()];
            [btn addTarget:self action:@selector(respondsToShowRightBtn) forControlEvents:UIControlEventTouchUpInside];
            btn;
        });
    }
    return _showRightBtn;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
